package com.fly.office.example;

import com.fly.office.word.model.table.StyleModel;
import com.fly.office.word.model.table.TableModel;
import com.fly.office.word.tool.WordTool;
import com.fly.office.word.util.TableUtil;
import com.fly.office.word.util.TextUtil;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

import java.util.*;


/**
 * 常规测试案例(文本+表格)
 * @author lf
 */
public class Normal {

    public static void main(String[] args) throws Exception {
        String tplPath = "/word/text_table.docx";
        String outPath = "D:\\data\\word\\text_table.docx";

        XWPFDocument doc = WordTool.genDoc(tplPath);
        if(doc!=null) {

            Map<String,String> textMap = new HashMap<>();
            textMap.put("name","张三");
            textMap.put("age","30");
            textMap.put("love","旅游、听歌");

            TextUtil.doParagraphs(doc,textMap);

            TableModel model = initModel();
            model.setKey("table");

            TableUtil.doParagraphs(doc,model);

            WordTool.download(doc,outPath);

        }
    }

    private static TableModel initModel()
    {
        TableModel model = new TableModel();

        List<String> titles=new ArrayList<>();
        titles.add("序号");
        titles.add("学号");
        titles.add("姓名");
        titles.add("年龄");
        titles.add("班级");
        model.setTitles(titles);

        List<Map<String,String>> dataList=new ArrayList<>();
        Map<String,String> data=new LinkedHashMap<>();
        data.put("seq","1");
        data.put("no","G001");
        data.put("name","lucy");
        data.put("age","15");
        data.put("class","高三1班");
        dataList.add(data);
        data=new LinkedHashMap<>();
        data.put("seq","2");
        data.put("no","G002");
        data.put("name","李梅");
        data.put("age","15");
        data.put("class","高三1班");
        dataList.add(data);

        model.setDataList(dataList);

        //设置数据区域样式
        StyleModel dataStyle=new StyleModel();
        dataStyle.setBgColor("#ffffff");
        model.setDataStyle(dataStyle);

        return model;
    }

}
